package operate

import (
	"context"

	"MBTI/api/internal/svc"
	"MBTI/api/internal/types"
	"MBTI/rpc/student/stu"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddResultLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddResultLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddResultLogic {
	return &AddResultLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddResultLogic) AddResult(req *types.AddResultReq) (resp *types.Reply, err error) {
	// todo: add your logic here and delete this line
	IfAddSucResp, err := l.svcCtx.StudentRpc.AddStudent(l.ctx, &stu.AddStuReq{
		StudentNo: req.StudentNo,
		MBTI:      req.MBTI,
		Answer:    req.Answer,
	})
	if err != nil {
		return &types.Reply{Code: 110, Msg: "结果记录出错"}, err
	}
	if !IfAddSucResp.IsSuccess {
		return &types.Reply{Code: 110, Msg: "无法添加记录"}, nil
	}
	return &types.Reply{Code: 100, Msg: "结果已记录"}, nil
}
